package angel.core.freemarker;

import java.io.IOException;
import java.util.Map;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class I18nSource implements TemplateDirectiveModel {
	
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {

		if(params.isEmpty()){
			throw new IllegalArgumentException("Parameter is required");
		}
		////"${context}/prototype/nls/{locale}/support.html"
		String name = ((freemarker.template.SimpleScalar)params.get("name")).getAsString();
		String locale = ((freemarker.template.SimpleScalar)params.get("locale")).getAsString();
		env.getOut().write(name.replace("{locale}", locale));		
	}
		
}
